package com.qiyadeng.company.biz;

import java.util.HashMap;
import java.util.Random;
import java.util.Set;

public class RandomUtils {
	
	//根据要生成多少券号产生相应的券号
	public static Set<Integer> genSixRandomCouponCode(int totalNum){
		HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
	    int START = 100000;
	    int END = 999999;
	    Random random = new Random();
	    while(hashMap.size()<totalNum){
	    	int randomInteger =  getRandomInteger(START, END, random);
	    	hashMap.put(randomInteger, "");
	    }
	    return hashMap.keySet();
	}
	
	//产生一个6为数字验证码
	public static String genSixRandomCode(){
		int START = 100000;
	    int END = 999999;
	    Random random = new Random();
	    int randomInteger =  getRandomInteger(START, END, random);
	    return randomInteger+"";
	}
	
	//产生六位随机数字密码
	public static String getSixRandomPassword(){
	    int START = 100000;
	    int END = 999999;
	    Random random = new Random();
	    int randomInteger =  getRandomInteger(START, END, random);
	    return randomInteger+"";
	}

	public static Integer getRandomInteger(int aStart, int aEnd, Random aRandom) {
		if (aStart > aEnd) {
			throw new IllegalArgumentException("Start cannot exceed End.");
		}
		// get the range, casting to long to avoid overflow problems
		long range = (long) aEnd - (long) aStart + 1;
		// compute a fraction of the range, 0 <= frac < range
		long fraction = (long) (range * aRandom.nextDouble());
		int randomNumber = (int) (fraction + aStart);
		return randomNumber;
	}
}
